#[derive(Debug)]
struct User {
    username: String,
    email: String,
    sign_in_count: u64,
    active: bool,
}

impl User {
    fn say_hi(&self) {
        println!("Hi {}[len={}], welcome your {} visits!", 
            self.username, 
            self.username.len(), 
            self.sign_in_count);
    }
    fn full_name(&self) -> String {
        format!("{} <{}>", self.username, self.email)
    }
    fn new_user(username: &str) -> User {
        User {
            username: String::from(username),
            email: format!("{}@qq.com", username),
            sign_in_count: 1,
            active: true,
        }
    }
}

struct Point(i32, i32);
impl Point {
    fn print(&self) {
        println!("x={}, y={}", self.0, self.1);
    }
}

fn structs() {
    let user1 = User {
        username: String::from("mike"),
        email: String::from("i@eaxi.com"),
        sign_in_count: 123_000,
        active: true,
    };
    println!("Hello {:?}", user1);

    let user2 = User {
        username: String::from("海哥"),
        email: String::from("haige@eaxi.com"),
        ..user1
    };
    println!("Hello {}, your detail: {:#?}", user2.full_name(), user2);
    user2.say_hi();

    User {
        username: String::from("Здравствуйте"),
        ..user2
    }.say_hi();

    let username = String::from("Carl Marks");
    User {username, ..user1}.say_hi();
    User::new_user("mikeliang").say_hi();

    Point(12, 89).print();
}